package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareDictEntity3;
import com.sgb.knowledgeshare.view.fragment.ShareVideoPlayListFragment;
import com.sgb.knowledgeshare.weight.ControllerView;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import com.swgk.core.view.entity.VideoListEntity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by fq on 2020/9/11 0011
 * Description：
 */
public class ShareVideoPlayListModel extends ViewModel {
    ShareVideoPlayListFragment fragment;
    private ArrayList<Long> delectList;

   

    public void getVideoTypeList(int page, String type) {
        Map map = new HashMap();
        map.put("pageNum",page);
        map.put("pageSize",10);
        map.put("type",type);//类型id
        ShareConfig.getInstance().getApi().getVideoListByType(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {

            }
        });
    }

    //获取评论数量
    public void getCommentNum(VideoBean videoData, ControllerView controllerView) {
        Map map = new HashMap();
        map.put("videoId", videoData.getVideoId());//longitude
        ShareConfig.getInstance().getApi().getCommentCount(map).enqueue(new ICallBack<BaseEntity<ShareDictEntity3>>() {
            @Override
            public void onSuccess(BaseEntity<ShareDictEntity3> data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    videoData.setCommentCount(Integer.parseInt(data.getData().getParam()));
                }
            }
        });
    }


    //点赞的操作
    public void setLike(String s) {
        Map map = new HashMap();
        map.put("videoId", s);//longitude
        ShareConfig.getInstance().getApi().getlike(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {

            }
        });
    }

    /*
     * 点击+号关注的实现
     * */
    public void getFens(String userid) {
        Map map = new HashMap();
        map.put("userNo",userid );
        ShareConfig.getInstance().getApi().getfens(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }
    /*
     * 视频播放次数实现
     * */
    public void getplayVideo(String videoId) {
        Map map = new HashMap();
        map.put("videoId",videoId );
        ShareConfig.getInstance().getApi().getplayVideos(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {

            }
        });
    }

    public void deleteMyVideo(int id) {
        delectList = new ArrayList<>();
        delectList.add((long) id);
        DialogHelper.showProgressDialog(fragment.getContext(), null, "删除中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getDeleteMyVideo(delectList).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    MToast.showToast(fragment.getContext(), "删除视频成功！");
                } else {
                    MToast.showToast(fragment.getContext(), data.getMsg());
                }
            }
        });
    }


    public void setActivity(ShareVideoPlayListFragment shareVideoPlayListFragment) {
        fragment = shareVideoPlayListFragment;
    }
}
